package cn.swh.guguanjia.controller;

import cn.swh.guguanjia.entity.Result;
import cn.swh.guguanjia.entity.SysUser;
import cn.swh.guguanjia.service.SysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import java.util.Date;
import java.util.Map;

//用户管理
@RestController
@RequestMapping("/mapper/userList")
public class SysUserController {

    @Autowired
    SysUserService service;


    @RequestMapping("")
    public ModelAndView index(){
        return new ModelAndView("/user/user-list.html");
    }

    @RequestMapping("index")
    public Result listAll() {
        return new Result(service.selectAll());
    }


    @RequestMapping("selectPage/{pageNum}/{pageSize}")
    public Result selectPage(@PathVariable("pageNum") int pageNum, @PathVariable("pageSize") int pageSize,@RequestParam Map<String,Object>map) {
        return new Result(service.selectPage(pageNum, pageSize,map));
    }

    @RequestMapping("selectById")
    public Result selectById(long rid){
        return new Result(true,"成功",service.selectById(rid));
    }

    @RequestMapping("selectNoRole")
    public Result selectNoRole(long rid,long oid){
        return new Result(true,"成功",service.selectNoRole(rid,oid));
    }

    @RequestMapping("Details")
    public ModelAndView Details() {
        return new ModelAndView("/user/user-detail.html");
    }

    @RequestMapping("toUpdate")
    public ModelAndView toUpdate() {
        return new ModelAndView("/user/user-save.html");
    }

    @RequestMapping(value = "doUpdate",method = RequestMethod.POST)
    public Result doUpdate(@RequestBody SysUser user) {
        return new Result(service.updateByPrimaryKeySelective(user));
    }

    //添加
    @RequestMapping(value = "insert", method = RequestMethod.POST)
    public Result insert(@RequestBody SysUser user) {
        user.setCreateDate(new Date());
        user.setUpdateDate(new Date());
        user.setDelFlag("0");
        user.setOfficeId(27L);
        user.setCompanyId(27L);
        return new Result(true,"添加成功",service.insertSelective(user));
    }



}
